package cn.han.jdbc;

import javax.swing.*;
import java.sql.*;

public class Test1 {
    public static void main(String[] args) throws Exception {
        /*1.注册驱动
         * 2.获取数据库的连接（用户名/密码）
         * 3.获取传输器
         * 4.执行SQL
         * 5.处理数据库返回的结果
         * 6.释放资源*/

        //1.
        Class.forName("com.mysql.jdbc.Driver");
        //2.jdbc连接MySQL数据库的协议//地址：端口号/数据库名字
        String url = "jdbc:mysql://localhost:3306/cgb2018";
        Connection c = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/cgb2018",
                "root","root");
        String sql = "select * from dept where uname = ?";//SQL骨架

        Statement s = c.createStatement();
        //4.
        ResultSet r = s.executeQuery(sql);//executeQuery查询操作executeUpdate增删改操作
        //5.
        while (r.next()){
            int a = r.getInt(1);
            System.out.print(a+"\t");
            String s1 = r.getString(2);
            System.out.print(s1+"\t");
                    String s2 = r.getString(3);
            System.out.println(s2);
            System.out.println(a+s1+s2);

        }
        //6.
        r.close();
        s.close();
        c.close();

    }
}
